﻿using System;
using System.Data;
using System.Text;
using System.Data.SQLite;//Please add references
namespace Bussiness
{
    /// <summary>
    /// 类Store。
    /// </summary>
    [Serializable]
    public partial class Store
    {
        public Store()
        { }
        #region Model
        private int _id;
        private string _store;
        private string _logo;
        private string _returns;
        private string _shipping;
        private string _payment;
        private string _replies;
        private string _feedback;
        private string _faq;
        /// <summary>
        /// 
        /// </summary>
        public int id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string store
        {
            set { _store = value; }
            get { return _store; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Logo
        {
            set { _logo = value; }
            get { return _logo; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Returns
        {
            set { _returns = value; }
            get { return _returns; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Shipping
        {
            set { _shipping = value; }
            get { return _shipping; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Payment
        {
            set { _payment = value; }
            get { return _payment; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Replies
        {
            set { _replies = value; }
            get { return _replies; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Feedback
        {
            set { _feedback = value; }
            get { return _feedback; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string FAQ
        {
            set { _faq = value; }
            get { return _faq; }
        }
        #endregion Model


        #region  Method

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Store(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,Store,Logo,Returns,Shipping,Payment,Replies,Feedback,FAQ ");
            strSql.Append(" FROM [Store] ");
            strSql.Append(" where id=@id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@id",  DbType.Int32,4)};
            parameters[0].Value = id;

            DataSet ds = SqliteHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    this.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Store"] != null && ds.Tables[0].Rows[0]["Store"].ToString() != "")
                {
                    this.store = ds.Tables[0].Rows[0]["Store"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Logo"] != null && ds.Tables[0].Rows[0]["Logo"].ToString() != "")
                {
                    this.Logo = ds.Tables[0].Rows[0]["Logo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Returns"] != null && ds.Tables[0].Rows[0]["Returns"].ToString() != "")
                {
                    this.Returns = ds.Tables[0].Rows[0]["Returns"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Shipping"] != null && ds.Tables[0].Rows[0]["Shipping"].ToString() != "")
                {
                    this.Shipping = ds.Tables[0].Rows[0]["Shipping"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Payment"] != null && ds.Tables[0].Rows[0]["Payment"].ToString() != "")
                {
                    this.Payment = ds.Tables[0].Rows[0]["Payment"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Replies"] != null && ds.Tables[0].Rows[0]["Replies"].ToString() != "")
                {
                    this.Replies = ds.Tables[0].Rows[0]["Replies"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Feedback"] != null && ds.Tables[0].Rows[0]["Feedback"].ToString() != "")
                {
                    this.Feedback = ds.Tables[0].Rows[0]["Feedback"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FAQ"] != null && ds.Tables[0].Rows[0]["FAQ"].ToString() != "")
                {
                    this.FAQ = ds.Tables[0].Rows[0]["FAQ"].ToString();
                }
            }
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from [Store]");
            strSql.Append(" where id=@id ");

            SQLiteParameter[] parameters = {
					new SQLiteParameter("@id", DbType.Int32,4)};
            parameters[0].Value = id;

            return SqliteHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [Store] (");
            strSql.Append("Store,Logo,Returns,Shipping,Payment,Replies,Feedback,FAQ)");
            strSql.Append(" values (");
            strSql.Append("@Store,@Logo,@Returns,@Shipping,@Payment,@Replies,@Feedback,@FAQ)");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@Store", DbType.String),
					new SQLiteParameter("@Logo", DbType.String),
					new SQLiteParameter("@Returns", DbType.String),
					new SQLiteParameter("@Shipping", DbType.String),
					new SQLiteParameter("@Payment", DbType.String),
					new SQLiteParameter("@Replies", DbType.String),
					new SQLiteParameter("@Feedback", DbType.String),
					new SQLiteParameter("@FAQ", DbType.String)};
            parameters[0].Value = store;
            parameters[1].Value = Logo;
            parameters[2].Value = Returns;
            parameters[3].Value = Shipping;
            parameters[4].Value = Payment;
            parameters[5].Value = Replies;
            parameters[6].Value = Feedback;
            parameters[7].Value = FAQ;

            return SqliteHelper.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update [Store] set ");
            strSql.Append("Store=@Store,");
            strSql.Append("Logo=@Logo,");
            strSql.Append("Returns=@Returns,");
            strSql.Append("Shipping=@Shipping,");
            strSql.Append("Payment=@Payment,");
            strSql.Append("Replies=@Replies,");
            strSql.Append("Feedback=@Feedback,");
            strSql.Append("FAQ=@FAQ");
            strSql.Append(" where id=@id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@Store", DbType.String),
					new SQLiteParameter("@Logo", DbType.String),
					new SQLiteParameter("@Returns", DbType.String),
					new SQLiteParameter("@Shipping", DbType.String),
					new SQLiteParameter("@Payment", DbType.String),
					new SQLiteParameter("@Replies", DbType.String),
					new SQLiteParameter("@Feedback", DbType.String),
					new SQLiteParameter("@FAQ", DbType.String),
					new SQLiteParameter("@id", DbType.Int32,8)};
            parameters[0].Value = store;
            parameters[1].Value = Logo;
            parameters[2].Value = Returns;
            parameters[3].Value = Shipping;
            parameters[4].Value = Payment;
            parameters[5].Value = Replies;
            parameters[6].Value = Feedback;
            parameters[7].Value = FAQ;
            parameters[8].Value = id;

            int rows = SqliteHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [Store] ");
            strSql.Append(" where id=@id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@id", DbType.Int32,4)};
            parameters[0].Value = id;

            int rows = SqliteHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,Store,Logo,Returns,Shipping,Payment,Replies,Feedback,FAQ ");
            strSql.Append(" FROM [Store] ");
            strSql.Append(" where id=@id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@id", DbType.Int32,4)};
            parameters[0].Value = id;

            DataSet ds = SqliteHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    this.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Store"] != null && ds.Tables[0].Rows[0]["Store"].ToString() != "")
                {
                    this.store = ds.Tables[0].Rows[0]["Store"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Logo"] != null && ds.Tables[0].Rows[0]["Logo"].ToString() != "")
                {
                    this.Logo = ds.Tables[0].Rows[0]["Logo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Returns"] != null && ds.Tables[0].Rows[0]["Returns"].ToString() != "")
                {
                    this.Returns = ds.Tables[0].Rows[0]["Returns"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Shipping"] != null && ds.Tables[0].Rows[0]["Shipping"].ToString() != "")
                {
                    this.Shipping = ds.Tables[0].Rows[0]["Shipping"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Payment"] != null && ds.Tables[0].Rows[0]["Payment"].ToString() != "")
                {
                    this.Payment = ds.Tables[0].Rows[0]["Payment"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Replies"] != null && ds.Tables[0].Rows[0]["Replies"].ToString() != "")
                {
                    this.Replies = ds.Tables[0].Rows[0]["Replies"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Feedback"] != null && ds.Tables[0].Rows[0]["Feedback"].ToString() != "")
                {
                    this.Feedback = ds.Tables[0].Rows[0]["Feedback"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FAQ"] != null && ds.Tables[0].Rows[0]["FAQ"].ToString() != "")
                {
                    this.FAQ = ds.Tables[0].Rows[0]["FAQ"].ToString();
                }
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM [Store] ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SqliteHelper.Query(strSql.ToString());
        }

        #endregion  Method
    }
}

